<?php

/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 */
 


/**
 *  @file
 *  @Author Samuel Maura
 *  Session utility functions
 *
 */
 
 function sessionPrint($val){
   echo (isset($_SESSION[$val])) ? $_SESSION[$val]:'';
 }
 
 
  function sessionDelete($val){
    //destroy session data on disk
    session_destroy();
    // delete session cookie
    if ($val !== null){
      setcookie(session_name($val),'',time() - 3600);
    }
    else{
      setcookie(session_name(),'',time() - 1000,'/');
    }
    
    // Destroy session array
    
    $_SESSION = array();
 }
 
 
 function checkErrors($val,$direct){
  if ($_SESSION[$val] != ''){
     header("Location: {$direct}");
     exit();
  }
}


function savePost(){
  foreach ($_POST as $key => $val){
    $_SESSION[''.$key.''] = $val;
  }
}

function clearPost(){
  foreach ($_POST as $key => $val){
    unset($_SESSION[''.$key.'']) ;
  }
}


function removeHtmlTags($val){
  if (is_array($val)){
      array_map('strip_tags',$val);
  }
  else if ($val != ''){
    $val = strip_tags($val);
  }
  else{
    trigger_error("This function expects an array or a scalar", E_USER_ERROR);
  }  
  return $val;
}


function trimInputArray($val){
    if (is_array($val)){
      array_map('trim',$val);
    }
    else{
      trigger_error("This function expects an array", E_USER_ERROR);
    }
    
  return $val;  
}


function lowerCase($val){
  if (is_array($val)){
      array_map('strtolower',$val);
    }
    else{
      trigger_error("This function expects an array", E_USER_ERROR);
    }
  return $val;  
}

 
?>